package org.offsync.async
import org.offsync.rich._
import org.offsync.util._
import java.nio.channels.SelectableChannel
import java.nio.channels.Selector
import java.nio.channels.spi.SelectorProvider
import java.nio.channels.ServerSocketChannel
import java.net.InetSocketAddress
import java.net.InetAddress
import java.nio.channels.SelectionKey
import java.util.concurrent.atomic.AtomicInteger
import org.offsync.nio.NioOpSelector

case class AsyncService extends DisposableBase {  val disposer = new Disposer();  trait OnThreadExit {    def onThreadExit() = disposer.dispose()  };  val acceptor = disposer.disposes(new AcceptSelector {    override def onThreadExit() = disposer.dispose()  });  val connector = disposer.disposes(new ConnectSelector {    override def onThreadExit() = disposer.dispose()  });  val reader = disposer.disposes(new ReadSelector {    override def onThreadExit() = disposer.dispose()  });  val writer = disposer.disposes(new WriteSelector {    override def onThreadExit() = disposer.dispose()  });    try {    acceptor.start();    connector.start();    reader.start();    writer.start();  } catch { case e =>    disposer.dispose();    throw e  };    protected override def onDispose(): Unit = {    disposer.dispose();    super.onDispose()  }}
